/**
 * Project: report2imolike
 * File name: transformer.h
 * Description:  This class is the main backend for processing data from IMO report
 *
 * @author Vladimir Burgić, Petnica Meteor Group http://meteori.rs, Copyright (C) 2011.
 * @version 0.2
 *
 * @see The GNU Public License 3 (GPL)
 */
/*
 *   This file is part of report2imolike project.
 *
 *   Report2imolike is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Report2imolike is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with report2imolike.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TRANSFORMER_H
#define TRANSFORMER_H

#include <QObject>
#include <QString>
#include <QMultiHash>
#include <QStringList>


class Transformer : public QObject
{
    Q_OBJECT
public:
    explicit Transformer(QObject * parent = 0);
    /*
    These functions should write everything to desired files returning 0. Error codes are:
    1 - bad input file format
    2 - no file for solar longitudes
    3 - input file not readable
    4 - output dir not writable
    */
    enum ERR_CODES {OK, BadFileFormat, NoSolLongFile, UnaccessibleInputFile, UnaccessibleOutputDir};

    void convert();
    void convert(QStringList & rateLines, QStringList & magLines);

    //if one wishes to manage everything from outside, I won't mind
    static ERR_CODES convert2files (QString inputFileName, QString solLongFileName, QString outputDirName="", QString infix="");
    static ERR_CODES convert2strings (QString inputFileName, QString solLongFileName, QStringList & rateLine, QStringList & magLine);


public slots:
    void setOutputDir (const QString & dirName);
    void setSolLongFile (const QString &solLongFileName);
    void setInputFiles (const QString & inputFileName);
    void setInputFiles (const QStringList & inputFileNames);
    void setInfix (const QString & infix);

signals:
    void parsingOutcome(const int &);
    void parsable2string(bool);
    void parsable2file(bool);

private:
    static bool parse (QMultiHash<QString, QString> inputData, QStringList showers, QStringList period, QStringList distribution, QString solLongFileName, QStringList & rateLines, QStringList & magLines);
    static QString getSolLong (QString solLongFileName, QString timeStart, QString timeEnd, QString date);
    static int hhmm2minutes(int timeAsString);

    QString outputDirName, solLongFileName, infix;
    QStringList inputFileNamesList;

    // headers that we need for RATE and MAG file
    static QString rateHeader;
    static QString magHeader;
};

#endif // TRANSFORMER_H
